import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import '../../model/cart_model.dart';
import './cart_count.dart';
import 'package:provide/provide.dart';
import '../../provide/cart_provide.dart';

class CartItem extends StatelessWidget {
  final CartInfoModel item;
  CartItem(this.item) ;

  @override
  Widget build(BuildContext context) {
    print('>>>>>$item');
    return Container(
      margin: EdgeInsets.fromLTRB(5.0,2.0, 5.0, 2.0),
      padding: EdgeInsets.fromLTRB(5.0,10.0, 5.0, 10.0),
      decoration: BoxDecoration(
        color:Colors.white,
        border: Border(
          bottom:BorderSide(width: 1.0,color:Colors.black26)
        )
      ),
      child: Row(
        children: <Widget>[
            _cartCheckBut(context,item),
            _cartImage(item.images),
            _cartgoodsName(context,item),
            _cartGoodsPrice(context,item)
        ],
      ),
    );
  }

 // 多选按钮 
  Widget _cartCheckBut(context, item){
    
    return Container(
      child: Checkbox(
        // 是不是选中
        value: item.isCheck,
        // 选中颜色
        activeColor: Colors.pink,
        onChanged: (bool val){
          print('${item.isCheck}');
          print('是不是选中$val');
          item.isCheck = val;
          Provide.value<CartProvide>(context).changCheckState(item);
        },
      ),
    );
  }

  // 商品图片
  Widget _cartImage(String image){
    return Container(
      width: ScreenUtil().setWidth(150),
      padding: EdgeInsets.all(3.0),
      decoration: BoxDecoration(
        border: Border.all(width: 1.0,color: Colors.black12)
      ),
      child: Image.network(image),
    );
  }

  // 商品名称
  Widget _cartgoodsName(context, item){
    return Container(
      width: ScreenUtil().setWidth(300),
      padding: EdgeInsets.all(10.0),
      alignment: Alignment.topLeft,
      child: Column(
        children: <Widget>[
          Text(item.goodsName),
          CartCount(item)
        ],
      ),
    );
  }

  // price价格
  Widget _cartGoodsPrice(context, item){
    return Container(
      width: ScreenUtil().setWidth(150.0),
      alignment: Alignment.centerRight,
      child: Column(
        children: <Widget>[
          Text('￥${item.price}'),
          Container(
            child: InkWell(
              onTap: (){ 
                 Provide.value<CartProvide>(context).deleteGoods(item.goodsId);
              },
              child: Icon(
                Icons.delete,
                color: Colors.black12,
                size: 30,
              ),
            ),
          )

        ],
      ),
    );
  }
}